<header class="header navbar bg-white shadow">

    <div class="pull-right offscreen-right btn-group tool-button">
        <a class="btn btn-primary navbar-btn" onclick="_selectOn()">确定</a>
    </div>
</header>
<section class="content-wrap bg-white">
    <div class=panel-body style="padding-top: 50px;">
        <div class="table-responsive no-border">
            <table id="datatable_select" class="table table-bordered table-striped mg-t datatable">
                <thead>
                <tr>
                    <th><%if("channel"==type){%>栏目名称<%}else{%>文章标题<%}%></th>
            </table>
        </div>
    </div>
</section>
<script language="JavaScript">
    var datatable_select;
    function initdatatable_select() {
        datatable_select = $('#datatable_select').DataTable({
            "dom": '<"toolbar">frtip',
            "searching":false,
            "processing": false,
            "serverSide": true,
            "select": true,
            "ordering": true,
            "language": {
                "url": "${base}/assets/plugins/datatables/cn.json"
            },
            "ajax": {
                "url": "${base}/platform/wx/conf/menu/cmsData/${type}",
                "type": "post",
                "data": function (d) {
                }
            },
            "order": [[0, "desc"]],
            "columns": [
                <%if("channel"==type){%>{"data": "name", "bSortable": true}<%}else{%>{"data": "title", "bSortable": true}<%}%>

            ]
        });
        datatable_select.on('click', 'tr', function () {

            if ( $(this).hasClass('selected') ) {
                $(this).removeClass('selected');
            }
            else {
                datatable_select.$('tr.selected').removeClass('selected');
                $(this).addClass('selected');
            }

        });
    }
    <%if("channel"==type){%>
        function _selectOn() {
            var chks = datatable_select.rows('.selected').data();
            if (chks.length > 0) {
                var ids = [];
                var str='';
                $.each(chks, function (i, n) {
                    str+= n.id;
                });
                $("#url").val("${AppDomain}${base}/public/wx/cms/channel/"+str);
                $("#dialogSelect").modal("hide");
            }else{
                Toast.warning("请先选择内容！");
            }
        }
    <%}else{%>
        function _selectOn() {
            var chks = datatable_select.rows('.selected').data();
            if (chks.length > 0) {
                var ids = [];
                var str='';
                $.each(chks, function (i, n) {
                    str+= n.id;
                });
                $("#url").val("${AppDomain}${base}/public/wx/cms/article/"+str);
                $("#dialogSelect").modal("hide");
            }else{
                Toast.warning("请先选择内容！");
            }
        }

    <%}%>

    $(document).ready(function () {
        initdatatable_select();
    });

</script>
